Security News
Supply Chain Attack Detected in @solana/web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@travetto/di
Advanced tools
Dependency injection is provided as a best practice, and as a framework primitive. Dependency injection can be achieved in multiple ways to support different software patterns. Dependency injection only supports classes as the class is the lookup key.
Dependency injection revolves around the following paradigms:
@Injectable
decorator denotes that a class can be injected. @Injectable()
class CustomService {
async coolOperation() {
... work ...
}
}
@InjectableFactory
decorator denotes a static class method that produces an @Injectable
class Config {
@InjectableFactory()
static initService(): CoolService {
return new CoolService();
}
}
@Inject
decorator denotes a desire to inject a value directly @Injectable()
class CustomService {
@Inject()
private dependentService: DependentService;
async coolOperation() {
await this.dependentService.doWork();
}
}
@Injectable
constructor params @Injectable()
class CustomService {
constructor (private dependentService: DependentService) {}
async coolOperation() {
await this.dependentService.doWork();
}
}
@InjectableFactory
params class Config {
@InjectableFactory()
static initService(dependentService: DependentService): CustomService {
return new CustomService(dependentService);
}
}
Some times you will need to lookup a dependency dynamically, or you want to control the injection process at a more granular level. To achieve that you will need to directly access the DependencyRegistry
.
The registry allows for requesting a dependency by class reference.
@Injectable()
class Complex {}
class ManualLookup {
async invoke() {
const complex = await DependencyRegistry.getInstance(Complex);
}
}
In addition to the standard operations, you are able to create multiple versions of the same dependency by providing a qualifier at registration time and at injection time. This allows you to have multiple database connections, or multiple email services.
const USER_DB = Symbol('USER_DB');
const ASSET_DB = Symbol('ASSET_DB');
class DBConfig {
host: string;
}
class Factory {
@InjectableFactory(USER_DB)
getUserConfig(): DBConfig {
const conf = new DBConfig();
conf.host = 'user';
return conf;
}
@InjectableFactory(USER_DB)
getAssetConfig(): DBConfig {
const conf = new DBConfig();
conf.host = 'asset';
return conf;
}
}
class UserService {
constructor(@Inject(USER_DB) config:DBConfig) {}
}
FAQs
Dependency registration/management and injection support.
The npm package @travetto/di receives a total of 39 weekly downloads. As such, @travetto/di popularity was classified as not popular.
We found that @travetto/di demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.